#！/bin/bash
hive=$HIVE_HOME/bin/hive
# 可以输入日期；如果未输入日期取昨天的时间
if [ -n "$1" ]
then
  do_date=$1
else
 do_date=`date -d "-1 day" +%F`
fi

# 定义要执行的SQL
# get_json_object(json,'$.xxx') 后面的选取是jsonpath的写法
sql="
insert overwrite table dws.dws_member_start_day
partition(dt='$do_date')
select 
    device_id,
    concat_ws('|', collect_set(uid)),
    concat_ws('|', collect_set(app_v)),
    concat_ws('|', collect_set(os_type)),
    concat_ws('|', collect_set(language)),
    concat_ws('|', collect_set(channel)),
    concat_ws('|', collect_set(area)),
    concat_ws('|', collect_set(brand))
from dwd.dwd_start_log
	where dt = '$do_date'
	group by device_id
;
"
$hive -e "$sql"
